<template>
  <div id="popupbody" v-if="dialogVisible">
    <div class="popupbody-box">
      <div class="popupbody-title">
        <span>错误记录</span>
        <span class="el-icon-close" @click="closePOpup"></span>
      </div>
      <div class="popupbody-boxin" style="padding:10px;">
        <el-table :data="arryList"
                  height="400"
                  :stripe="tableStyle.tableStripe"
                  :border="tableStyle.tableBorder"
                  tooltip-effect="dark"
                  ref="table">
          <el-table-column label="ID" prop="id" align="center" width="50"></el-table-column>
          <el-table-column label="类型" align="center" prop="type"></el-table-column>
          <el-table-column label="内容" align="center" prop="content">
          </el-table-column>
          <el-table-column label="姓名" align="center" prop="user_name">
          </el-table-column>
          <el-table-column label="用户类型" align="center" prop="content">
            <template slot-scope="scope">
              <span v-if="scope.row.user_type==1">学生</span>
              <span v-if="scope.row.user_type==2">家长</span>
              <span v-if="scope.row.user_type==3">老师</span>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" prop="create_time" align="center"></el-table-column>
        </el-table>
        <el-pagination
            background
            layout="prev, pager, next"
            :current-page="page.pageindex"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </div>
      <div class="popupbody-footer">
        <el-button size="small" @click="closePOpup">返回</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import {facilityErrorIndex} from '@/api/admin/development'

export default {
  name: 'studentMultiple',
  props: ['visible', 'facilityId'],
  components: {},
  data() {
    return {
      versionsDetailVisible: false,
      dialogVisible: this.visible,
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [],
      // 搜索
      searchForm: {
        facility_id: 1
      },
      versionId: 0
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.InitFn()
      } else {
        this.page.pageindex = 1
        this.arryList = []
      }
    }
  },
  created() {
  },
  methods: {
    // 初始化
    async InitFn() {
      this.searchForm.p = this.page.pageindex
      facilityErrorIndex({
        facility_id: this.facilityId,
        p: this.page.pageindex
      }).then(res => {
        console.log('res:error:', res)
        this.arryList = res.list.data;
        this.page.total = res.list.total;
      })
      // let data = await this.$fetch(this.api.Developmental.faceFacility.version.index,this.searchForm)
      // this.arryList = data.list.data;
      // this.page.total = data.list.total;
    },
    // 搜索
    searchFn(option) {
      this.page.pageindex = 1
      this.searchForm = option
      this.InitFn()
    },
    // 行选中
    rowClick(option) {
      this.applyBookBox = option.name
      this.radio = option.id
      this.applyBox = option
    },
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 提交数据
    async submitFormAdd() {
      console.log('选中学生并关闭页面：', this.applyBox)
      this.$emit('studentFn', this.applyBox)
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    addVersionFn(id) {
      this.versionId = id || 0
      this.versionsDetailVisible = !this.versionsDetailVisible
    },
    handleDetel(index) {
      if (this.arryList[index].is_now) {
        this.$message.error('该版本当前正在使用不可删除')
        return
      }
      this.$confirm('确认永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(index)
      }).catch(() => {
      })
    },
    async detelRespon(index) {
      let data = await this.$post(this.api.Developmental.faceFacility.version.delete, {id: this.arryList[index].id})
      console.log(data)
      this.arryList.splice(index, 1)
      this.$message.success(data.msg)
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
.popupbody-boxin {
  min-width: 850px;
}
</style>
